<?php

namespace app\models;

use Yii;
use yii\db\Query;
/**
 * This is the model class for table "{{%cart}}".
 *
 * @property integer $id
 * @property integer $uid
 * @property integer $create_at
 * @property integer $status
 */
class ListHy extends \yii\db\ActiveRecord {

  public static function tableName()
    {
        return '{{%base_goods_hy}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['sp_id', 'hysl','xj', 'cs', 'qym', 'qdsl', 'status', 'statuses'], 'integer'],
            [['cpgn', 'fhdz'], 'string'],
            [['sczdj', 'bhsdj', 'hsdj', 'zk'], 'number'],
            [['gg', 'yxq', 'ccrq', 'mjgsxx', 'lxr', 'dhhm', 'fbsj'], 'string', 'max' => 25],
            [['spm'], 'string', 'max' => 128]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'hy_id' => '货源id',
            'sp_id' => '商品ID',
            'cpgn' => '产品功能',
            'hysl' => '货源数量',
            'qdsl' => '起订数量',
            'gg' => '规格',
            'sczdj' => '市场指导价',
            'bhsdj' => '不含税单价',
            'hsdj' => '含税单价',
            'yxq' => '有效期',
            'ccrq' => '出厂日期',
            'fhdz' => '发货地址',
            'mjgsxx' => '卖家公司信息',
            'xj' => '包装要求 是否新旧 新1 旧0',
            'cs' => '残损  完好1 残存0 ',
            'qym' => '区域码  有1 无0',
            'zk' => '折扣',
            'lxr' => '联系人',
            'dhhm' => '电话号码',
            'fbsj' => '发布时间',
            'status' => '0未审核，1已审核，-1禁用',
            'statuses' => '0下架，1上架',
            'spm' => '商品名',
        ];
    }
    
    public static function selBasegoods($array,$condition,$tag,$pages,$page1) {
        
//        print_r($condition);die();
        $pages=(int)$pages;
        
            $basegoods = (new Query())->select('a.*,b.*,c.company_name,c.phone')->from("dh_base_goods_hy as a")->leftJoin('dh_base_goods AS b','a.sp_id = b.id')->leftJoin("dh_sys_users as c","a.qy_id=c.id")->
                    Where($array)->andWhere('1=1'.$condition)->orderBy($tag)->limit($page1)->offset($pages)->all();
//            print_r($basegoods);die();
        return $basegoods;
    }
    
    
    
     public static function listBaseGoods($array,$condition) {
         
            $total = (new Query())->select('a.*,b.*')->from("dh_base_goods_hy as a")->
                        leftJoin('dh_base_goods AS b','a.sp_id = b.id')->Where($array)->andWhere('1=1'.$condition)->count();
        
        return $total;
    }
  
}
